import request from "@/utils/request";
import { AuditForm, ProjectLockOutEditForm } from "./types";

const currentSystem = localStorage.getItem("usertypeName");

/**
 * 获取停复工记录列表(分页)
 *
 * @param id
 */
export function QueryProjectLockOutList(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectLockOut/page`;
      break;
    case "Corp":
      url = `/api/v1/corp/projectLockOut/page`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectLockOut/page`;
      break;
    case "Manager":
      url = `/api/v1/manager/projectLockOut/page`;
      break;
    case "Commander":
      url = `/api/v1/commander/projectLockOut/page`;
      break;
    default:
      url = `/api/v1/manager/projectLockOut/page`;
  }
  return request({
    url: url,
    method: "GET",
    params: data,
  });
}

/**
 * 新增停复工记录
 *
 * @param id
 */
export function AddProjectLockOut(data: ProjectLockOutEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectLockOut/create`;
      break;
    case "Corp":
      url = `/api/v1/corp/projectLockOut/create`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectLockOut/create`;
      break;
    case "Manager":
      url = `/api/v1/manager/projectLockOut/create`;
      break;
    case "Commander":
      url = `/api/v1/commander/projectLockOut/create`;
      break;
    default:
      url = `/api/v1/manager/projectLockOut/create`;
  }
  return request({
    url: url,
    method: "POST",
    data: data,
  });
}

/**
 * 修改停复工记录
 * @param id
 * @param data
 * @returns
 */
export function UpdateProjectLockOut(id: number, data: ProjectLockOutEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectLockOut/update/${id}`;
      break;
    case "Corp":
      url = `/api/v1/corp/projectLockOut/update/${id}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectLockOut/update/${id}`;
      break;
    case "Manager":
      url = `/api/v1/manager/projectLockOut/update/${id}`;
      break;
    case "Commander":
      url = `/api/v1/commander/projectLockOut/update/${id}`;
      break;
    default:
      url = `/api/v1/manager/projectLockOut/update/${id}`;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}
/**
 * 获取停复工记录详情
 *
 * @param id
 */

export function GetProjectLockOutForm(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectLockOut/${id}`;
      break;
    case "Corp":
      url = `/api/v1/corp/projectLockOut/${id}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectLockOut/${id}`;

      break;
    case "Manager":
      url = `/api/v1/manager/projectLockOut/${id}`;
      break;
    case "Commander":
      url = `/api/v1/commander/projectLockOut/${id}`;
      break;
    default:
      url = `/api/v1/manager/projectLockOut/${id}`;
  }
  return request({
    url: url,
    method: "GET",
  });
}

/**
 * 获取停复工记录审核日志
 *
 * @param id
 */

export function GetAuditLogList(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectLockOut/auditLogs`;
      break;
    case "Corp":
      url = `/api/v1/corp/projectLockOut/auditLogs`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectLockOut/auditLogs`;

      break;
    case "Manager":
      url = `/api/v1/manager/projectLockOut/auditLogs`;
      break;
    case "Commander":
      url = `/api/v1/commander/projectLockOut/auditLogs`;
      break;
    default:
      url = `/api/v1/manager/projectLockOut/auditLogs`;
  }
  return request({
    url: url,
    method: "GET",
    params: {
      id: id,
    },
  });
}

/**
 * 审核停复工记录
 *
 * @param id
 */
export function AuditProjectLockOut(data: AuditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectLockOut/audit/` + data.id;
      break;
    case "Corp":
      url = `/api/v1/corp/projectLockOut/audit/` + data.id;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectLockOut/audit/` + data.id;
      break;
    case "Manager":
      url = `/api/v1/manager/projectLockOut/audit/` + data.id;
      break;
    case "Commander":
      url = `/api/v1/commander/projectLockOut/audit/` + data.id;
      break;
    default:
      url = `/api/v1/manager/projectLockOut/audit/` + data.id;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}
/**
 *删除停复工记录
 *
 * @param id
 */
export function DeleteProjectLockOut(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectLockOut/` + id;
      break;
    case "Corp":
      url = `/api/v1/corp/projectLockOut/` + id;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectLockOut/` + id;
      break;
    case "Manager":
      url = `/api/v1/manager/projectLockOut/` + id;
      break;
    case "Commander":
      url = `/api/v1/commander/projectLockOut/` + id;
      break;
    default:
      url = `/api/v1/manager/projectLockOut/` + id;
  }
  return request({
    url: url,
    method: "delete",
  });
}
